"""中间件统一入口"""

from fastapi import FastAPI

# 导入中间件
from backend.middleware.trace_middleware import TraceMiddleware
from backend.middleware.cors_middleware import setup_cors
from backend.middleware.exception_middleware import setup_exception_handlers
from backend.middleware.rate_limit_middleware import setup_rate_limiting
from backend.middleware.auth_middleware import setup_auth


def setup_middleware(app: FastAPI) -> None:
    """设置所有中间件
    
    Args:
        app: FastAPI应用实例
    """
    # 1. 请求跟踪中间件
    app.add_middleware(TraceMiddleware)
    
    # 2. CORS中间件
    setup_cors(app)
    
    # 3. 异常处理中间件
    setup_exception_handlers(app)
    
    # 4. 限流中间件
    setup_rate_limiting(app)
    
    # 5. 授权中间件
    setup_auth(app)

__all__ = [
    'setup_middleware',
    'TraceMiddleware'
]